package main

import "fmt"

// 结构体实现了接口的全部方法才叫实现这个接口
type USB interface {
	input()
	output()
}

func (mouse Mouse) input() {
	fmt.Println(mouse.name, "鼠标输入")
}
func (mouse Mouse) output() {
	fmt.Println(mouse.name, "鼠标输出")
}

type Mouse struct {
	name string
}

func (key Keyboard) input() {
	fmt.Println(key.name, "键盘输入")
}
func (key Keyboard) output() {
	fmt.Println(key.name, "键盘输出")
}

type Keyboard struct {
	name string
}

func Text(u USB) {
	u.input()
	u.output()
}

type A interface{}

func TextNow(a A) {
	fmt.Println(a)
}

// 空接口 在map或slice里使用可以接收任何类型
func TextNow2(temp interface{}) {
	fmt.Println(temp)
}

func main() {
	var m1 Mouse
	m1.name = "罗技"
	k1 := Keyboard{name: "雷蛇"}
	Text(m1)
	Text(k1)

	var usb USB
	usb = k1
	fmt.Println(usb)

	//接口是无法实现类的属性的
	//usb.name
	usb.input()
	anyMouse := Mouse{name: "any"}
	TextNow(anyMouse)

	var a1 int = 1
	var a2 string = "hahaha"
	var a3 Mouse = Mouse{name: "鼠标"}
	var a4 Mouse = Mouse{name: "键盘"}
	TextNow(a1)
	TextNow(a2)
	TextNow(a3)
	TextNow(a4)

	map1 := make(map[string]interface{})
	map1["a1"] = a1
	map1["a2"] = a2
	map1["a3"] = a3
	map1["a4"] = a4

	fmt.Println(map1["a3"])
	fmt.Println(map1)
}
